import path from "path";
import { app } from "electron";

/**
 * 获取当前程序目录
 * @returns
 */
function buildPath(ipath) {
  // const appPath = app.isPackaged
  //   ? path.dirname(app.getPath("exe"))
  //   : app.getAppPath();
  // return appPath;

  //MacOS
  if (process.platform == "darwin") {
    let resPath = app.isPackaged
      ? path.join(path.dirname(app.getPath("exe")), "../Resources/res", ipath)
      : path.join(process.cwd(), "/res", ipath);
    return resPath;
  }
  //Windows
  if (process.platform == "win32") {
    let resPath = app.isPackaged
      ? path.join(path.dirname(app.getPath("exe")), "/resources/res", ipath)
      : path.join(process.cwd(), "/res", ipath);
    return resPath;
  }

  let resPath = app.isPackaged
    ? path.join(path.dirname(app.getPath("exe")), "../resources/res", ipath)
    : path.join(process.cwd(), "/res", ipath);
  return resPath;
}

/**
 * 获取资源地址
 * @returns
 */
function getPath() {
  // const appPath = app.isPackaged
  //   ? path.dirname(app.getPath("exe"))
  //   : app.getAppPath();
  // return appPath;

  let resPath = app.isPackaged
    ? path.join(process.cwd(), "/resources/res")
    : path.join(process.cwd(), "/res");

  return resPath;
}

function getConfigPath() {
  return app.getPath("userData");
}

const RES = {
  buildPath,
  getPath,
  getConfigPath,
};

export default RES;
